package com.iraeta.controller.kaoqin;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.iraeta.controller.BaseController;
import com.iraeta.entity.main.Kaoqinyuan;
import com.iraeta.service.basic.KaoQinYuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController(value = "KaoQinYuanController")
@RequestMapping("kaoqinyuan")
public class KaoQinYuanController extends BaseController {
    @Autowired
    KaoQinYuanService kaoQinYuanService;

    @RequestMapping("pagekaoqinyuan")
    public String pageKaoqinyuan(@RequestBody JSONObject jo){
        this.pageSet(jo);
        List<Kaoqinyuan> kaoqinyuanList = kaoQinYuanService.listKaoQinYuan();
        PageInfo<Kaoqinyuan> kaoqinyuanPageInfo = this.getPageInfo(kaoqinyuanList);
        return this.success(kaoqinyuanPageInfo);
    }

    @RequestMapping("getkaoqinyuan")
    public String getKaoqinyuan(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        Kaoqinyuan item = kaoQinYuanService.getKaoQinYuan(id);
        return this.success(item);
    }

    @RequestMapping("addeditkaoqinyuan")
    public String addKaoqinyuan(@RequestBody JSONObject paramJb) {
        int id = paramJb.getIntValue("id");
        Kaoqinyuan item = id <= 0 ? new Kaoqinyuan() :  kaoQinYuanService.getKaoQinYuan(id);
        this.mapJsonToObj(paramJb, item);
        if(id <= 0) item.setId(0);
        if(id <= 0){
            kaoQinYuanService.addKaoQinYuan(item);
        }else {
            kaoQinYuanService.updateKaoQinYuan(item);
        }
        return this.success();
    }

    @RequestMapping("deletekaoqinyuan")
    public String deleteKaoqinyuan(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        kaoQinYuanService.deleteKaoQinYuan(id);
        return this.success();
    }

    @RequestMapping("listkaoqinyuan")
    public String listKaoqinyuan(){
        List<Kaoqinyuan> kaoqinyuanList = kaoQinYuanService.listKaoQinYuan();
        return this.success(kaoqinyuanList);
    }
}
